﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DemoData;
using DemoData.Model;
using NUnit.Framework;

namespace DemoDataTest.Providers
{
    [TestFixture]
    public class OrderProviderTest
    {
        [Test]
        public void DemoData_Providers_OrderProvider_Get()
        {
            Repository.PopulateDemoData();

            int itemCount = 0;

            foreach (Order order in Repository.Orders.Get().Where(o => o.Quantity > 2))
            {
                itemCount++;
            }

            Assert.AreNotEqual(0, itemCount);
        }

        [Test]
        public void DemoData_Providers_OrderProvider_GetOrders_Per_Customer()
        {
            Repository.PopulateDemoData();

            foreach (Customer customer in Repository.Customers.Get().Where(c => c.Firstname.StartsWith("aa", StringComparison.OrdinalIgnoreCase)))
            {
                foreach (Order foundOrder in Repository.Orders.Get().Where(order => order.CustomerId == customer.Id))
                {
                    Product product = Repository.Products.Get().FirstOrDefault(p => p.Id == foundOrder.Id);
                    if (product != null)
                    {
                        Console.WriteLine("Product: '" + product.ProductName + "', price: " + foundOrder.LineTotal);
                    }
                }
            }
        }
    }
}
